package com.xuexiang.xuidemo.page.text;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;

import com.xuexiang.xuidemo.page.base.BasePageAbilitySlice;
import com.xuexiang.xuidemo.page.base.PageUtils;

import java.util.ArrayList;

/**
 * Text扩展实现列表入口
 *
 * @since 2021-04-06
 */
public class TextAbility extends Ability {
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setMainRoute(ExtendTextListActivitySlice.class.getName());

        ArrayList<Class<? extends BasePageAbilitySlice>> routeClassList = new ArrayList<>();
        routeClassList.addAll(ExtendTextListActivitySlice.getDemoPages());
        routeClassList.addAll(SuperTextAbilitySlice.getSuperTextClasses());

        for (Class<? extends BasePageAbilitySlice> clz : routeClassList) {
            addActionRoute(PageUtils.getAction(clz), clz.getName());
        }
    }

    /**
     * 跳转到该Ability页面
     *
     * @param ability 上下文
     * @param action 跳转路由
     */
    public static void start(Ability ability, String action) {
        Intent intent = new Intent();
        intent.setOperation(new Intent.OperationBuilder()
            .withBundleName(ability.getBundleName())
            .withAbilityName(TextAbility.class)
            .withAction(action)
            .build());
        ability.startAbility(intent);
    }
}
